package com.nursery.clazz.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.nursery.clazz.dao.ClassInfoMapper;
import com.nursery.clazz.entity.ClassInfo;
import com.nursery.clazz.entity.ClassInfoExample;
import com.nursery.clazz.service.ClassInfoService;

@Service
public class ClassInfoServiceImpl implements ClassInfoService {

	@Autowired
	ClassInfoMapper classInfoMapper;

	public long countByExample(ClassInfoExample example) {
		return classInfoMapper.countByExample(example);
	}

	public void deleteByPrimaryKey(Integer id) throws Exception {
		classInfoMapper.deleteByPrimaryKey(id);
	}

	public void insert(ClassInfo record) throws Exception {
		classInfoMapper.insertSelective(record);
	}

	public List<ClassInfo> selectByExample(ClassInfoExample example) {
		return classInfoMapper.selectByExample(example);
	}

	public ClassInfo selectByPrimaryKey(Integer id) {
		return classInfoMapper.selectByPrimaryKey(id);
	}

	public void updateByPrimaryKeySelective(ClassInfo record) throws Exception {
		classInfoMapper.updateByPrimaryKeySelective(record);
	}

	public void updateByPrimaryKey(ClassInfo record) throws Exception {
		classInfoMapper.updateByPrimaryKey(record);
	}

	public String getNameByid(Integer id) {
		ClassInfoExample example = new ClassInfoExample();
		ClassInfoExample.Criteria criteria = example.createCriteria();
		criteria.andIdEqualTo(id);
		ClassInfo info = classInfoMapper.selectByExample(example).stream().findFirst().orElse(null);
		if (info == null) {
			return "";
		} else {
			return info.getClassName();
		}
	}

}
